package com.study.talk.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.CompoundButton
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.study.talk.R
import com.study.talk.ui.adapter.base.BaseListAdapter
import com.study.talk.databinding.UsersSelectItemBinding
import com.study.talk.data.model.UserInfo


class UsersSelectAdapter : BaseListAdapter<UserInfo, UsersSelectAdapter.ViewHolder>() {

    val selectMap: MutableMap<Int, Boolean> = HashMap()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            DataBindingUtil.inflate(LayoutInflater.from(parent.context), R.layout.users_select_item,parent,false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.binding.user = getItem(position)
        holder.binding.userListCheckedItemCheckbox.setOnCheckedChangeListener { _: CompoundButton, b: Boolean ->
            selectMap[getItem(position).id] = b
        }
    }

    class ViewHolder(val binding: UsersSelectItemBinding) : RecyclerView.ViewHolder(
        binding.root
    )
}
